/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIProduct.java
 *
 * Created on 01-04-2011, 21:43:36
 */

package GUILayer;

import ControlLayer.CtrProduct;
import ControlLayer.CtrSupplier;
import ModelLayer.Product;
import ModelLayer.Supplier;
import java.util.ArrayList;

/**
 *
 * @author Henrik-iMac
 */
public class GUIProduct extends javax.swing.JFrame {

    /** Creates new form GUIProduct */
    public GUIProduct() {
        initComponents();
        setVisible(true);
        //updateList();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        searchPanel = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        searchPartNoField = new javax.swing.JTextField();
        searchNameField = new javax.swing.JTextField();
        searchPurchasePriceField = new javax.swing.JTextField();
        searchSalesPriceField = new javax.swing.JTextField();
        searchRentPriceField = new javax.swing.JTextField();
        searchCOOField = new javax.swing.JTextField();
        searchMinStockField = new javax.swing.JTextField();
        searchSupplierIdField = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        searchStatusLabel = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        searchAmountField = new javax.swing.JTextField();
        insert = new javax.swing.JPanel();
        jLabel36 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jLabel40 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        jLabel43 = new javax.swing.JLabel();
        insertPartNoField = new javax.swing.JTextField();
        insertNameField = new javax.swing.JTextField();
        insertPurchasePriceField = new javax.swing.JTextField();
        insertSalesPriceField = new javax.swing.JTextField();
        insertRentPriceField = new javax.swing.JTextField();
        insertCOOField = new javax.swing.JTextField();
        insertMinStockField = new javax.swing.JTextField();
        insertSupplierIdField = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        insertStatusLabel = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        insertAmountField = new javax.swing.JTextField();
        updatePanel = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        updatePartNoField = new javax.swing.JTextField();
        updateNameField = new javax.swing.JTextField();
        updatePurchasePriceField = new javax.swing.JTextField();
        updateSalesPriceField = new javax.swing.JTextField();
        updateRentPriceField = new javax.swing.JTextField();
        updateCOOField = new javax.swing.JTextField();
        updateMinStockField = new javax.swing.JTextField();
        updateSupplierIdField = new javax.swing.JTextField();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        updateStatusLabel = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        updateAmountField = new javax.swing.JTextField();
        deletePanel = new javax.swing.JPanel();
        jLabel44 = new javax.swing.JLabel();
        jLabel45 = new javax.swing.JLabel();
        deletePartNoField = new javax.swing.JTextField();
        deleteNameField = new javax.swing.JTextField();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        deleteStatusLabel = new javax.swing.JLabel();
        allProdPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        loadButton = new javax.swing.JButton();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18));
        jLabel1.setText("Product");

        jLabel4.setText("Id");

        jLabel5.setText("Name");

        jLabel6.setText("Purchase price");

        jLabel7.setText("Sales price");

        jLabel8.setText("Rent price");

        jLabel9.setText("Country of origin");

        jLabel10.setText("Min stock");

        jLabel11.setText("Supplier ID");

        jButton1.setText("Search");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Clear");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel20.setText("Amount");

        javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
        searchPanel.setLayout(searchPanelLayout);
        searchPanelLayout.setHorizontalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addComponent(searchStatusLabel)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel20)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11))
                        .addGap(26, 26, 26)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(searchPartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(searchNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE)
                            .addComponent(searchCOOField, javax.swing.GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE)
                            .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(searchSupplierIdField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(searchMinStockField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
                            .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(searchAmountField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(searchRentPriceField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(searchSalesPriceField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(searchPurchasePriceField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        searchPanelLayout.setVerticalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(searchPartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(searchNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(searchAmountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(searchPurchasePriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(searchSalesPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(searchRentPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(searchCOOField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(searchMinStockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(searchSupplierIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(searchStatusLabel)
                .addContainerGap(120, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Search", searchPanel);

        jLabel36.setText("Id");

        jLabel37.setText("Name");

        jLabel38.setText("Purchase price");

        jLabel39.setText("Sales price");

        jLabel40.setText("Rent price");

        jLabel41.setText("Country of origin");

        jLabel42.setText("Min stock");

        jLabel43.setText("Supplier ID");

        jButton3.setText("Insert");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Clear");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel21.setText("Amount");

        javax.swing.GroupLayout insertLayout = new javax.swing.GroupLayout(insert);
        insert.setLayout(insertLayout);
        insertLayout.setHorizontalGroup(
            insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(insertLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(insertLayout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4))
                    .addComponent(insertStatusLabel)
                    .addGroup(insertLayout.createSequentialGroup()
                        .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel36)
                            .addComponent(jLabel37)
                            .addComponent(jLabel21)
                            .addComponent(jLabel38)
                            .addComponent(jLabel39)
                            .addComponent(jLabel40)
                            .addComponent(jLabel41)
                            .addComponent(jLabel42)
                            .addComponent(jLabel43))
                        .addGap(26, 26, 26)
                        .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(insertPartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(insertNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE)
                            .addComponent(insertCOOField, javax.swing.GroupLayout.DEFAULT_SIZE, 782, Short.MAX_VALUE)
                            .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(insertSupplierIdField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(insertMinStockField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
                            .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(insertAmountField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(insertRentPriceField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(insertSalesPriceField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(insertPurchasePriceField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        insertLayout.setVerticalGroup(
            insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(insertLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel36)
                    .addComponent(insertPartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel37)
                    .addComponent(insertNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(insertAmountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel38)
                    .addComponent(insertPurchasePriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel39)
                    .addComponent(insertSalesPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel40)
                    .addComponent(insertRentPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel41)
                    .addComponent(insertCOOField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel42)
                    .addComponent(insertMinStockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel43)
                    .addComponent(insertSupplierIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(insertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(insertStatusLabel)
                .addContainerGap(120, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Insert", insert);

        jLabel12.setText("Id");

        jLabel13.setText("Name");

        jLabel14.setText("Purchase price");

        jLabel15.setText("Sales price");

        jLabel16.setText("Rent price");

        jLabel17.setText("Country of origin");

        jLabel18.setText("Min stock");

        jLabel19.setText("Supplier ID");

        jButton5.setText("Update");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Clear");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel22.setText("Amount");

        updateAmountField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateAmountFieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout updatePanelLayout = new javax.swing.GroupLayout(updatePanel);
        updatePanel.setLayout(updatePanelLayout);
        updatePanelLayout.setHorizontalGroup(
            updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(updatePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(updatePanelLayout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6))
                    .addComponent(updateStatusLabel)
                    .addGroup(updatePanelLayout.createSequentialGroup()
                        .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16)
                            .addComponent(jLabel17)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13)
                            .addComponent(jLabel22))
                        .addGap(29, 29, 29)
                        .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(updatePanelLayout.createSequentialGroup()
                                .addComponent(updatePartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(241, 241, 241))
                            .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(updateSupplierIdField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(updateMinStockField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(updateCOOField, javax.swing.GroupLayout.DEFAULT_SIZE, 779, Short.MAX_VALUE)
                            .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(updateAmountField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(updateRentPriceField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(updateSalesPriceField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(updatePurchasePriceField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
                            .addComponent(updateNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 779, Short.MAX_VALUE))))
                .addContainerGap())
        );
        updatePanelLayout.setVerticalGroup(
            updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(updatePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(updatePartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(updateNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(updateAmountField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(updatePurchasePriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(updateSalesPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(updateRentPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(updateCOOField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(updateMinStockField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(updateSupplierIdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(updatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(updateStatusLabel)
                .addContainerGap(120, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Update", updatePanel);

        jLabel44.setText("Id");

        jLabel45.setText("Name");

        jButton7.setText("Delete");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Clear");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout deletePanelLayout = new javax.swing.GroupLayout(deletePanel);
        deletePanel.setLayout(deletePanelLayout);
        deletePanelLayout.setHorizontalGroup(
            deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deletePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(deletePanelLayout.createSequentialGroup()
                        .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel44)
                            .addComponent(jLabel45))
                        .addGap(83, 83, 83)
                        .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(deletePartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(deleteNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 779, Short.MAX_VALUE)))
                    .addGroup(deletePanelLayout.createSequentialGroup()
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8))
                    .addComponent(deleteStatusLabel))
                .addContainerGap())
        );
        deletePanelLayout.setVerticalGroup(
            deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deletePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel44)
                    .addComponent(deletePartNoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel45)
                    .addComponent(deleteNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(deletePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(jButton8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteStatusLabel)
                .addContainerGap(314, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Delete", deletePanel);

        jList1.setFont(new java.awt.Font("Courier New", 0, 11)); // NOI18N
        jScrollPane1.setViewportView(jList1);

        jLabel2.setText("Part#");

        jLabel3.setText("Name");

        loadButton.setText("Load");
        loadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadButtonActionPerformed(evt);
            }
        });

        jLabel23.setText("Purchase");

        jLabel24.setText("Sales price");

        jLabel25.setText("Rent price");

        jLabel26.setText("Country of origin");

        jLabel27.setText("Min stock");

        jLabel28.setText("Supplier Id");

        jLabel29.setText("Amount");

        jLabel30.setText("price");

        javax.swing.GroupLayout allProdPanelLayout = new javax.swing.GroupLayout(allProdPanel);
        allProdPanel.setLayout(allProdPanelLayout);
        allProdPanelLayout.setHorizontalGroup(
            allProdPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(allProdPanelLayout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addGap(93, 93, 93)
                .addComponent(jLabel29)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(allProdPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel23)
                    .addComponent(jLabel30))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel24)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel25)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel26)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel27)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel28)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(loadButton)
                .addContainerGap(303, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 909, Short.MAX_VALUE)
        );
        allProdPanelLayout.setVerticalGroup(
            allProdPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(allProdPanelLayout.createSequentialGroup()
                .addGroup(allProdPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel29)
                    .addComponent(jLabel23)
                    .addComponent(jLabel24)
                    .addComponent(jLabel25)
                    .addComponent(jLabel26)
                    .addComponent(jLabel27)
                    .addComponent(jLabel28)
                    .addComponent(loadButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel30)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("All products", allProdPanel);

        jMenu1.setText("Navigation");

        jMenuItem1.setText("Main menu");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(842, Short.MAX_VALUE))
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 914, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        setVisible(false);
        GUIMainMenu gui = new GUIMainMenu();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        search();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        insert();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        update();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
        clear();
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        delete();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void updateAmountFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateAmountFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_updateAmountFieldActionPerformed

    private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed
        // TODO add your handling code here:
        updateList();
    }//GEN-LAST:event_loadButtonActionPerformed


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIProduct().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel allProdPanel;
    private javax.swing.JTextField deleteNameField;
    private javax.swing.JPanel deletePanel;
    private javax.swing.JTextField deletePartNoField;
    private javax.swing.JLabel deleteStatusLabel;
    private javax.swing.JPanel insert;
    private javax.swing.JTextField insertAmountField;
    private javax.swing.JTextField insertCOOField;
    private javax.swing.JTextField insertMinStockField;
    private javax.swing.JTextField insertNameField;
    private javax.swing.JTextField insertPartNoField;
    private javax.swing.JTextField insertPurchasePriceField;
    private javax.swing.JTextField insertRentPriceField;
    private javax.swing.JTextField insertSalesPriceField;
    private javax.swing.JLabel insertStatusLabel;
    private javax.swing.JTextField insertSupplierIdField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton loadButton;
    private javax.swing.JTextField searchAmountField;
    private javax.swing.JTextField searchCOOField;
    private javax.swing.JTextField searchMinStockField;
    private javax.swing.JTextField searchNameField;
    private javax.swing.JPanel searchPanel;
    private javax.swing.JTextField searchPartNoField;
    private javax.swing.JTextField searchPurchasePriceField;
    private javax.swing.JTextField searchRentPriceField;
    private javax.swing.JTextField searchSalesPriceField;
    private javax.swing.JLabel searchStatusLabel;
    private javax.swing.JTextField searchSupplierIdField;
    private javax.swing.JTextField updateAmountField;
    private javax.swing.JTextField updateCOOField;
    private javax.swing.JTextField updateMinStockField;
    private javax.swing.JTextField updateNameField;
    private javax.swing.JPanel updatePanel;
    private javax.swing.JTextField updatePartNoField;
    private javax.swing.JTextField updatePurchasePriceField;
    private javax.swing.JTextField updateRentPriceField;
    private javax.swing.JTextField updateSalesPriceField;
    private javax.swing.JLabel updateStatusLabel;
    private javax.swing.JTextField updateSupplierIdField;
    // End of variables declaration//GEN-END:variables
    
    private void search(){
        CtrProduct ctrProd = new CtrProduct();
        String input = searchPartNoField.getText();
        if(input.length() == 0)
        {
            input = searchNameField.getText();
            if(input.length() == 0){
                searchStatusLabel.setText("Insert id or name");
            }
            else{
                Product product = new Product();
                product = ctrProd.findProductByName(input, true);
                putValuesOnTheScreen(product);
            }
        }
        else{
            Product product = new Product();
            product = ctrProd.findProductByPartNo(Integer.parseInt(input), true);
            putValuesOnTheScreen(product);
        }
    }

    private void putValuesOnTheScreen(Product product){
        searchPartNoField.setText(String.valueOf(product.getPartNo()));
        searchNameField.setText(product.getName());
        searchAmountField.setText(String.valueOf(product.getAmount()));
        searchPurchasePriceField.setText(String.valueOf(product.getPurchasePrice()));
        searchSalesPriceField.setText(String.valueOf(product.getSalesPrice()));
        searchRentPriceField.setText(String.valueOf(product.getRentPrice()));
        searchCOOField.setText(product.getCountryOfOrigin());
        searchMinStockField.setText(String.valueOf(product.getMinStock()));
        searchSupplierIdField.setText(String.valueOf(product.getSupplierId().getId()));

        updatePartNoField.setText(String.valueOf(product.getPartNo()));
        updateNameField.setText(product.getName());
        updateAmountField.setText(String.valueOf(product.getAmount()));
        updatePurchasePriceField.setText(String.valueOf(product.getPurchasePrice()));
        updateSalesPriceField.setText(String.valueOf(product.getSalesPrice()));
        updateRentPriceField.setText(String.valueOf(product.getRentPrice()));
        updateCOOField.setText(product.getCountryOfOrigin());
        updateMinStockField.setText(String.valueOf(product.getMinStock()));
        updateSupplierIdField.setText(String.valueOf(product.getSupplierId().getId()));

        deletePartNoField.setText(String.valueOf(product.getPartNo()));
        deleteNameField.setText(product.getName());
    }

    private void clear(){
        searchPartNoField.setText(null);
        searchNameField.setText(null);
        searchPurchasePriceField.setText(null);
        searchSalesPriceField.setText(null);
        searchRentPriceField.setText(null);
        searchCOOField.setText(null);
        searchMinStockField.setText(null);
        searchSupplierIdField.setText(null);
        searchStatusLabel.setText(null);

        updatePartNoField.setText(null);
        updateNameField.setText(null);
        updatePurchasePriceField.setText(null);
        updateSalesPriceField.setText(null);
        updateRentPriceField.setText(null);
        updateCOOField.setText(null);
        updateMinStockField.setText(null);
        updateSupplierIdField.setText(null);
        updateStatusLabel.setText(null);

        deletePartNoField.setText(null);
        deleteNameField.setText(null);
        deleteStatusLabel.setText(null);
    }

    private void insert(){
        CtrProduct ctrProd = new CtrProduct();
        CtrSupplier ctrSupp = new CtrSupplier();
        Product pObj = new Product();
        String name = insertNameField.getText();
        int amount = Integer.parseInt(insertAmountField.getText());
        double purchasePrice = Double.parseDouble(insertPurchasePriceField.getText());
        double salesPrice = Double.parseDouble(insertSalesPriceField.getText());
        double rentPrice = Double.parseDouble(insertRentPriceField.getText());
        String coo = insertCOOField.getText();
        int minStock = Integer.parseInt(insertMinStockField.getText());
        Supplier supp = ctrSupp.findSupplierById(Integer.parseInt(insertSupplierIdField.getText()), false);

        pObj.setName(name);
        pObj.setAmount(amount);
        pObj.setPurchasePrice(purchasePrice);
        pObj.setSalesPrice(salesPrice);
        pObj.setRentPrice(rentPrice);
        pObj.setCountryOfOrigin(coo);
        pObj.setMinStock(minStock);
        pObj.setSupplierId(supp);
        int result = ctrProd.insertProduct(pObj);
        if (result == 1){
            clear();
            insertStatusLabel.setText(name + " is inserted with id: " + pObj.getPartNo());
        }
        else{
            insertStatusLabel.setText("Something went wrong");
        }
    }

    private void update(){
        CtrProduct ctrProduct = new CtrProduct();
        int partNo = Integer.parseInt(updatePartNoField.getText());
        System.out.println("+" + partNo + "+");

        String name = updateNameField.getText();
        int amount = Integer.parseInt(updateAmountField.getText());
        double purchasePrice = Double.parseDouble(updatePurchasePriceField.getText());
        double salesPrice = Double.parseDouble(updateSalesPriceField.getText());
        double rentPrice = Double.parseDouble(updateRentPriceField.getText());
        String coo = updateCOOField.getText();
        int minStock = Integer.parseInt(updateMinStockField.getText());
        Supplier sid = ctrProduct.findProductByPartNo(partNo, false).getSupplierId();

        int result = ctrProduct.updateProduct(partNo, name, amount, purchasePrice, salesPrice,
                rentPrice, coo, minStock);
        if (result == 1){
            clear();
            updateStatusLabel.setText("Product is updated");
        }
        else{
            updateStatusLabel.setText("Problem with update");
        }
    }

    private void delete(){
        CtrProduct ctrProd = new CtrProduct();
        int partNo = Integer.parseInt(deletePartNoField.getText());
        int result = ctrProd.deleteProduct(partNo);
        if(result == 1)
        {
            clear();
            deleteStatusLabel.setText("Product with " + partNo + " is deleted");
        }
        else{
            deleteStatusLabel.setText("Something went wrong!");
        }
    }
    private void updateList()
    {
        CtrProduct ctrProd = new CtrProduct();
        ArrayList<Product> prod = ctrProd.findAllProducts(true);
        buildList(prod);
    }

    private void buildList(ArrayList<Product> products)
    {
        String [] product = new String[products.size()];
        int index = 0;
        for(Product pObj : products)
        {
            String partNo = String.valueOf(pObj.getPartNo());
            String name = pObj.getName();
            String amount = String.valueOf(pObj.getAmount());
            String purchasePrice = String.valueOf(pObj.getPurchasePrice());
            String salesPrice = String.valueOf(pObj.getSalesPrice());
            String rentPrice = String.valueOf(pObj.getRentPrice());
            String cOO = pObj.getCountryOfOrigin();
            String minStock = String.valueOf(pObj.getMinStock());
            String supplierId = String.valueOf(pObj.getSupplierId().getId());

            if(partNo.length() < 3){
                int length = partNo.length();
                while (length < 3)
                {
                    partNo = partNo + " ";
                    length++;
                }
            }
            if(name.length() >20){
                name = name.substring(0, 19);
            }
            if(name.length() < 20){
                int length = name.length();
                while (length < 19)
                {
                    name = name + " ";
                    length++;
                }
            }
            if(amount.length() < 5){
                int length = amount.length();
                while (length < 5)
                {
                    amount = amount + " ";
                    length++;
                }
            }
            if(purchasePrice.length() < 6){
                int length = purchasePrice.length();
                while (length < 6)
                {
                    purchasePrice = purchasePrice + " ";
                    length++;
                }
            }
            if(salesPrice.length() < 6){
                int length = salesPrice.length();
                while (length < 6)
                {
                    salesPrice = salesPrice + " ";
                    length++;
                }
            }
            if(rentPrice.length() < 6){
                int length = rentPrice.length();
                while (length < 6)
                {
                    rentPrice = rentPrice + " ";
                    length++;
                }
            }
            if(cOO.length() >15){
                cOO = cOO.substring(0, 14);
            }
            if(cOO.length() < 15){
                int length = cOO.length();
                while (length < 14)
                {
                    cOO = cOO + " ";
                    length++;
                }
            }
            if(minStock.length() < 5){
                int length = minStock.length();
                while (length < 5)
                {
                    minStock = minStock + " ";
                    length++;
                }
            }

            product[index] = (partNo + " " + name + " " + amount + " " + purchasePrice + "   " +
                    salesPrice + "    " + rentPrice + "   " + cOO + " " + minStock +
                    "   " + supplierId);
            index++;
        }
        jList1.setListData(product);
    }
}
